<?php
require_once("../../inc/global.php");
$upload_name = "Filedata";
function Get_File_extend($FilePath){
	$extend = pathinfo($FilePath);
	$extend = strtolower($extend["extension"]);
	return $extend;
}

//生成文件夹
function mkdirm($path){ 
	if (!file_exists($path)){ 
		mkdirm(dirname($path)); 
		mkdir($path, 0777); 
	} 
} 

$attdir="/upimg/".date('Ym')."/";
$upfile_max=1024*1000; //kb
$ufile=$_FILES[$upload_name];
$upfile_ext="jpg,png,gif,bmp";  //可以上传的格式
$notextend_array=array("asp","aspx","cs","php","jsp","do","js","html","shtml","jhtml","htm","phtml");  //系统不能上传的文件格式
$upfile_error=array("0"=>"正确","1"=>"文件大小超出了服务器的限制","2"=>"要上传的文件大小超出浏览器限制","3"=>"文件仅部分被上传","4"=>"没有找到要上传的文件","5"=>"服务器临时文件夹丢失","6"=>"文件写入到临时文件夹出错");
$extend_array=explode(",",$upfile_ext);
	if(intval($ufile["error"])!==0){
		echo "ERROR:{$ufile["error"]}";
		exit(0);
	}
	if(in_array(Get_File_extend($ufile["name"]),$notextend_array)){
		echo "ERROR:7";
		exit(0);
	}
	if(!in_array(Get_File_extend($ufile["name"]),$extend_array)){
		echo "ERROR:7";
		exit(0);
	}
	if(($upfile_max*1024)<$ufile["size"]){
		echo "ERROR:8";
		exit(0);
	}
	//生成文件夹
	if(!file_exists(SITEROOT.$attdir)){
		mkdirm(SITEROOT.$attdir);
		//mkdir($upfilepath);
	}
	
	$uploadfile=$attdir.uniqid().".".Get_File_extend($ufile["name"]); 
	if(!move_uploaded_file($ufile["tmp_name"],SITEROOT.$uploadfile)){
		echo "ERROR:9";
		//echo "ERROR:上传文件出错";
	}else{
		echo "FILEID:" .$uploadfile;
	}

?>